package nil.ed.simulator.request.ui.jfx.manager;

import javafx.application.Platform;
import javafx.scene.Node;
import nil.ed.simulator.request.ui.jfx.controller.RightControlPaneController;
import nil.ed.simulator.request.ui.jfx.controller.TableViewController;
import nil.ed.simulator.request.ui.jfx.controller.TopControlPaneController;
import nil.ed.simulator.request.ui.jfx.ui.Controller;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ControllerManager {
    private static final Map<String, Node> controllerMap = new ConcurrentHashMap<>();

    public static void addController(Controller controller) {
        controllerMap.put(controller.getClass().getSimpleName(), (Node) controller);
    }

    public static RightControlPaneController getRight() {
        return get(RightControlPaneController.class);
    }

    public static TableViewController getTable() {
        return get(TableViewController.class);
    }

    public static TopControlPaneController getTop() {
        return get(TopControlPaneController.class);
    }

    @SuppressWarnings("unchecked")
    private static <T> T get(Class<T> clazz) {
        return (T) controllerMap.get(clazz.getSimpleName());
    }

}
